package com.yyplatform.admin.platform.role.controller;

import static com.yyplatform.admin.Constants.URL_PREFIX;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yyplatform.admin.infra.model.RestResponse;
import com.yyplatform.admin.platform.role.model.dto.SysLoginHisDTO;
import com.yyplatform.admin.platform.role.model.dto.SysLoginHisQueryDTO;
import com.yyplatform.admin.platform.role.service.SysLoginHisService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * Created on 2024-09-18
 */
@Slf4j
@Tag(name = "用户/登录日志管理")
@AllArgsConstructor
@RestController
@RequestMapping(URL_PREFIX + "/sys/loginHis/")
public class SysLoginHisController {

    private SysLoginHisService sysLoginHisService;


    @GetMapping("query")
    @Operation(summary = "查询")
    @RequiresPermissions("sys:loginHis:query")
    public RestResponse<Page<SysLoginHisDTO>> query(SysLoginHisQueryDTO queryDTO) {
        log.debug("query dto = {}", queryDTO);

        Page<SysLoginHisDTO> page = sysLoginHisService.query(queryDTO);

        return RestResponse.ok(page);
    }

    @PostMapping("delete")
    @Operation(summary = "删除")
    @RequiresPermissions("sys:loginHis:delete")
    public RestResponse<Void> delete(Long id) {
        log.debug("delete by id is {}", id);

        sysLoginHisService.delete(id);
        return RestResponse.ok(null);
    }


    @PostMapping("deleteAll")
    @Operation(summary = "批量删除")
    @RequiresPermissions("sys:loginHis:deleteAll")
    public RestResponse<Void> deleteBatch() {

        sysLoginHisService.deleteAll();
        return RestResponse.ok(null);
    }


}
